package regex;
/*
* 数量词
* X?:X字符出现0次或1次
* X*:X字符至少出现0次或者多次(>=1)
* X+:X字符出现1次及以上
*
* X{n}:X字符出现n次
* X{n,}:X字符至少出现n次
* X{n,m}:X字符出现[n,m]次
* */
public class RegexDemo05 {
    public static void main(String[] args) {
        //method01();
        //method02();
        //method03();
        System.out.println("aaaa".matches("a{4}"));//true
        System.out.println("aaaaa".matches("a{4}"));//false
        System.out.println("aaa".matches("a{1,}"));//true
        System.out.println("".matches("a{1,}"));//false
        System.out.println("aaaaa".matches("a{4,6}"));//true
        System.out.println("aaaaaa".matches("a{4,6}"));//true


        System.out.println("acdef".matches("[a-z]{5}"));//true
    }

    private static void method03() {
        System.out.println("aaa".matches("a+"));//true
        System.out.println("".matches("a+"));//false
        System.out.println("abb".matches("a+b+"));//true
    }

    private static void method02() {
        System.out.println("a".matches("a*"));//true
        System.out.println("aaaa".matches("a*"));//true
        System.out.println("".matches("a*"));//true
    }

    private static void method01() {
        System.out.println("a".matches("a?"));//true
        System.out.println("aa".matches("a?"));//false
        System.out.println("b".matches("a?"));//false
    }
}
